#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <vector>

using namespace std;

int bases[12];
int tops[12];
double freqRatio[12];

void Extend(vector<double>& freqList)
{
	int i = 12;
	int fold = 1;
	while(i < 91)
	{
		int rem = i % 12;
		if (rem == 0)
			fold *= 2;
		freqList[i] = freqList[rem] * fold;
		++i;
	}
}
void Adjust192(vector<double>& freqList)
{
}
void WellTemp(vector<double>& freqList, double lowC)
{
	double twelfth = pow(2.0, 1.0/12.0);
	for ( int i = 0; i<12; ++i)
	{
		freqList[i]= lowC*pow(twelfth, i);
	}
	Extend(freqList);
}


void HammondTemp(vector<double>& freqList, double lowC, int gearMax)
{
	double twelfth = pow( 2.0, 1.0/12.0 );
	double freq[12];
    double err[12];
	int i;
	for (i = 0; i < 12 ; ++i)
	{
		freq[i] = pow( twelfth, i );
		err[i] = 999.9;
	}
	int base, top;
	for ( base = gearMax/2 ; base >= 1  ; -- base)
	{
		for ( top = 1; top < base * 2 ; ++ top )
		{
			double tempfreq = (double) top / (double) base ;
			for( i = 0; i < 12 ; ++i )
			{
				double temperr = fabs ( tempfreq - freq[i] );
				if( temperr <= err[i] )
				{
					bases[i] = base;
					tops[i] = top;
					err[i] = temperr;
					freqRatio[i] = tempfreq;
				}
			}
		}
	}

	for (int i=0; i<12; ++i)
	{
		freqList[i] = lowC *( (double)tops[i] / bases[i]);
	}

	Extend(freqList);
	Adjust192(freqList);
}

int main(int argc, char *argv[])
{
    if(argc != 3)
    {
        cerr<< "command CENTRAL_C GEAR_MAX" <<endl;
        exit (0);
    }
    int gearMax = atoi(argv[2]);
    double centralC = atof(argv[1]);

	vector<double> freqList(91);
	
    double lowC = centralC / 8;
	
	if(gearMax == 0)
	{
		WellTemp(freqList, lowC);
	}
	else
	{
		HammondTemp(freqList,lowC, gearMax);
	}
	
	cout << "Central_C : " << centralC << ", GearMax: " << gearMax<<endl;
	cout << freqList.size() <<endl;
	for ( int i = 0 ; i < freqList.size(); ++i )
	{
		cout <<setprecision(10)<<freqList[i] <<endl;
	}

    return 0;
}
